package org.ysu.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.ysu.common.JsonResult;
import org.ysu.pojo.InterViewList;
import org.ysu.pojo.Interview;
import org.ysu.pojo.InterviewForm;
import org.ysu.service.InterviewService;
import org.ysu.utils.FileUploadUtils;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/interview")
public class InterviewController {

        @Autowired
        private InterviewService interviewService;

//        //根据乡村干部id查询走访信息
//        @GetMapping("/get")
//        public List<Interview> getInterviewByid(Integer id){
//            return interviewService.getInterviewByid(id);
//        }

        //新增走访信息时，传乡村干部id，贫困户id，户主id，走访时间，交谈详细、风险类型、风险备注、年收入、债务、意见与建议、配图
        @RequestMapping("/add")
        public JsonResult addInterview(@RequestBody  Interview interview){
            interview.setCreateTime(new Date());
            Integer i =interviewService.addInterview(interview);
            return new JsonResult(i>0?1:0,i>0?"success":"fail",null);
        }


    /***
     * 干部id得到他所帮扶的对象
     * @param id
     * @return
     */
    @RequestMapping("/getInterviewById/{id}")
    public JsonResult getInterviewById(@PathVariable Integer id){
        InterViewList interview = interviewService.getInterviewByid(id);
        return new JsonResult(1,"success",interview);
    }

    /**
     * 根据条件查询信息
     * @param interviewForm
     * @return
     */
    @RequestMapping("/getInterviewsByPara")
    public JsonResult getInterviewsByPara(@RequestBody InterviewForm interviewForm){
        InterViewList interview = interviewService.getInterviewsByPara(interviewForm);
        return new JsonResult(1,"success",interview);
    }

}
